package com.zhaoxi.project.hrp.controller;

import java.util.List;

import com.zhaoxi.project.hrp.domain.HrpPartner;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.project.hrp.service.impl.HrpPartnerServiceImpl;
import com.zhaoxi.framework.web.BaseService;
import com.zhaoxi.framework.web.PageData;
import com.zhaoxi.common.utils.poi.ExcelUtil;
import com.zhaoxi.framework.web.page.TableDataInfo;

/**
 * 合作伙伴Controller
 *
 * @author zhaoxi
 * @date 2023-07-07
 */
@Tag(name = "partner",description = "合作伙伴partner是人员表的基层表，sys_user，hrp_lead，sys_tenant等表都是拓展表")
@RestController
@RequestMapping("/hrp/partner")
public class HrpPartnerController extends BaseService {
    @Autowired
    private HrpPartnerServiceImpl HrpPartnerService;

    /**
     * 查询合作伙伴列表
     */
    @Operation(summary = "查询联系人列表，分页返回")
    @Parameter(description = "联系人对象", required = false)
    @PreAuthorize("@ss.hasPermi('hrp:partner:list')")
    @GetMapping("/list")
    public TableDataInfo list(HrpPartner hrpPartner) {
        startPage();
        List<HrpPartner> list = HrpPartnerService.selectHrpPartnerList(hrpPartner);
        return getDataTable(list);
    }

    /**
     * 导出合作伙伴列表
     */
    @PreAuthorize("@ss.hasPermi('hrp:partner:export')")
    @Log(title = "合作伙伴", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HrpPartner hrpPartner) {
        List<HrpPartner> list = HrpPartnerService.selectHrpPartnerList(hrpPartner);
        ExcelUtil<HrpPartner> util = new ExcelUtil<HrpPartner>(HrpPartner.class);
        util.exportExcel(response, list, "合作伙伴数据");
    }

    /**
     * 获取合作伙伴详细信息
     */
    @PreAuthorize("@ss.hasPermi('hrp:partner:query')")
    @GetMapping(value = "/{id}")
    public PageData getInfo(@PathVariable("id") Long id) {
        return success(HrpPartnerService.selectHrpPartnerById(id));
    }

    /**
     * 新增合作伙伴
     */
    @PreAuthorize("@ss.hasPermi('hrp:partner:add')")
    @Log(title = "合作伙伴", businessType = BusinessType.INSERT)
    @PostMapping
    public PageData add(@RequestBody HrpPartner hrpPartner) {
        hrpPartner.setCreateBy(this.getUsername());
        hrpPartner.setUpdateBy(this.getUsername());
        return toAjax(HrpPartnerService.insertHrpPartner(hrpPartner));
    }

    /**
     * 修改合作伙伴
     */
    @PreAuthorize("@ss.hasPermi('hrp:partner:edit')")
    @Log(title = "合作伙伴", businessType = BusinessType.UPDATE)
    @PutMapping
    public PageData edit(@RequestBody HrpPartner hrpPartner) {
        hrpPartner.setUpdateBy(this.getUsername());
        return toAjax(HrpPartnerService.updateHrpPartner(hrpPartner));
    }

    /**
     * 删除合作伙伴
     */
    @PreAuthorize("@ss.hasPermi('hrp:partner:remove')")
    @Log(title = "合作伙伴", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public PageData remove(@PathVariable Long[] ids) {
        return toAjax(HrpPartnerService.deleteHrpPartnerByIds(ids));
    }
}
